package com.softserve.dao;

import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.softserve.entity.Student;

public class StudentDAOMockImpl implements StudentDAO{
	
	private static Map<Long, Student> studentMap = new HashMap<Long, Student>();
	private static Long studentIndex = 0L;
	
	static {
		Student student1 = new Student();
		student1.setId(++studentIndex);
		student1.setName("Andriy Kucher");
		student1.setFacultyName("Aplied Mathematics");
		student1.setDob(getDate(1,11,1982));
		student1.setDoe(getDate(1,9,1999));
		studentMap.put(student1.getId(), student1);
		
		Student student2 = new Student();
		student2.setId(++studentIndex);
		student2.setName("Yevhen Sobko");
		student2.setFacultyName("Computer Science");
		student2.setDob(getDate(3,01,1983));
		student2.setDoe(getDate(2,9,2000));
		studentMap.put(student2.getId(), student2);		
	}

	public Long addStudent(Student student) {
		Student newStudent = student.clone();
		newStudent.setId(++studentIndex);
		studentMap.put(newStudent.getId(), newStudent);
		return newStudent.getId();
	}


	public void deleteStudent(Long studentId) {
		studentMap.remove(studentId);
	}

	public Student getStudent(Long studentId) {
		return studentMap.get(studentId);
	}

	public Collection<Student> getAllStudents() {
		return studentMap.values();
	}	
	
	public void updateStudent(Student student) {
		studentMap.put(student.getId(), student.clone());
	}

	private static Date getDate(int day, int month, int year) {
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, day);
		return cal.getTime();
	}

	
}
